package com.softline.documentsmall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softline.documentsmall.entity.RelateJournalArtical;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.RelateJournalArticalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author wph
 * @Date 2021/2/3 15:17
 */
@Api(value = "后台管理___论文接口", tags = {"后台管理___论文接口"})
@RestController
@RequestMapping("/extend/journalArtical")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class RelateJournalArticalController {
    @Autowired
    private RelateJournalArticalService relateJournalArticalService;

    @ApiOperation(value = "查询论文列表", notes = "查询论文列表")
    @GetMapping(value = "/list")
    public ReturnVO list(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "title", required = false) String title, @RequestParam(name = "dicId", required = false) Integer dictionaryId) {
        QueryWrapper<RelateJournalArtical> queryWrapper = new QueryWrapper<>();
        if (dictionaryId!=null&&dictionaryId!=0){
            queryWrapper.eq("dictionary_id",dictionaryId);
        }
        if (title != null && "".equals(title)) {
            queryWrapper.like("title", title);
        }
        Page<RelateJournalArtical> result = new Page<>();
        List<RelateJournalArtical> records = relateJournalArticalService.selectList(title,dictionaryId,pageNo,pageSize);
        Long count = Long.valueOf(relateJournalArticalService.selectCount(title,dictionaryId));
        result.setRecords(records);
        result.setCurrent(pageNo);
        result.setSize(pageSize);
        result.setTotal(count);
        return ReturnVOUtils.success(result);
    }

    @ApiOperation(value = "查询论文详情", notes = "查询论文详情")
    @GetMapping(value = "/selectById")
    public RelateJournalArtical selectById(@RequestParam(name = "id") int id) {
        return relateJournalArticalService.selectById(id);
    }

    @ApiOperation(value = "新增论文", notes = "新增论文")
    @PostMapping(value = "/insert")
    public ReturnVO insert(@RequestBody RelateJournalArtical relateJournalArtical) {
        return relateJournalArticalService.insert(relateJournalArtical);
    }

    @ApiOperation(value = "修改论文", notes = "修改论文")
    @PostMapping(value = "/update")
    public ReturnVO update(@RequestBody @Valid RelateJournalArtical relateJournalArtical) {
        return relateJournalArticalService.updateRelateBookById(relateJournalArtical);
    }

}
